const common = require('./base/common');
const HashBucket = require('./dataStruct/hashBucket').HashBucket;


let hashBucketTesting = function(items, group, cycle = false) {
    let bucket = new HashBucket(items, group);
    
    for(let i=0; i < 10000; ++i) {
        bucket.getItem(parseInt(Math.random() * 10000), cycle);
    }

    return bucket.unHits;
}

let casesGenerator = function() {
    function randItems(num) {
        let items = [];
        for(let i=0; i < num; ++i) {
            items.push(Math.random());
        }
        return items;
    }

    return [
        [randItems(1000), 1],
        [randItems(1000), 3],
        [randItems(5000), 3],
        [randItems(5000), 14],
        [randItems(4000), 157],
        [randItems(8000), 157],
        [randItems(10000), 311]
    ];
};

console.log("环式轮询未命中次数：");
common.testing(casesGenerator())(x => hashBucketTesting(x[0], x[1], true));
console.log("冷门桶排序未命中次数排序：");
common.testing(casesGenerator())(x => hashBucketTesting(x[0], x[1], false));
